<template>
  <div>
    <div
      class="add"
      v-if="active == 0"
      @click="add()"
    >新增</div>
    <eagle-list
      showTab
      :tabData="tabData"
      @initActive="_initActive"
      @bindData="bindData"
      :filterParams="filterParams"
      :filterParamsDefaul="filterTabDefault"
      :filterTab="filterTab"
      allowSearch
      :placeholder="placeholder1"
      ref="eaglelist"
    >
      <div v-if="this.active === 0">
        <eagle-cell
          style="margin-top: 10px"
          class="card"
          v-for="(item, index) in list"
          :key="index"
        >
          <div>
            <div @click="goToDetail(item)">
              <div class="warn_header">
                <div>姓名：{{ item.ChnName }}</div>
              </div>
              <eagle-row
                gutter="20"
                class="dep_sort"
              >
                <eagle-col span="24">
                  <img
                    class="icon"
                    src="@/assets/Images/AppIcon/icon_list_user.png"
                    alt=""
                  />部门：{{ item.OrgName ? item.OrgName : "无" }}
                </eagle-col>
              </eagle-row>

              <eagle-row
                gutter="20"
                class="dep_sort"
              >
                <eagle-col span="24">
                  <img
                    class="icon"
                    src="@/assets/Images/AppIcon/icon_list_user.png"
                    alt=""
                  />岗位：{{ item.PostName }}
                </eagle-col>
              </eagle-row>

              <eagle-row
                gutter="20"
                class="dep_sort"
              >
                <eagle-col span="24">
                  <img
                    class="icon"
                    src="@/assets/Images/AppIcon/icon_list_user.png"
                    alt=""
                  />录入人：{{ item.CreateChnName }}
                </eagle-col>
              </eagle-row>
              <eagle-row
                gutter="20"
                class="dep_sort"
              >
                <eagle-col span="24">
                  <img
                    class="icon"
                    src="@/assets/Images/AppIcon/icon_list_date.png"
                    alt=""
                  />录入时间：{{ item.CreateDate | formatDateTime }}
                </eagle-col>
              </eagle-row>
              <eagle-file-read-only
                :attachs="item.MainAttach"
                :labelName="'签名文件:'"
              ></eagle-file-read-only>
            </div>
            <van-divider />
            <div class="op_btn">
              <div
                class="btn_item"
                v-if="item.Status !=-1"
                @click="del(item)"
              >
                <img
                  src="@/assets/Images/AppIcon/icon_list_abolish.png"
                  alt=""
                />
                <div class="mr-10">废止</div>
              </div>
              <div
                class="btn_item"
                v-if="item.Status !=-1"
                @click="goToEdit(item)"
              >
                <img
                  src="@/assets/Images/AppIcon/icon_list_edit.png"
                  alt=""
                />
                <div class="mr-10">编辑</div>
              </div>
            </div>
          </div>
        </eagle-cell>
      </div>
      <div v-if="this.active === 1">
        <eagle-cell
          style="margin-top: 10px"
          class="card"
          v-for="(item, index) in list"
          :key="index"
        >
          <div class="warn_item">
            <div @click="lookPdf(item)">
              <eagle-row class="dep_sort">
                <eagle-col span="24">
                  <img
                    class="icon"
                    src="@/assets/Images/AppIcon/icon_list_post.png"
                    alt=""
                  />最近修改人：{{ item.EditChnName }}
                </eagle-col>
              </eagle-row>
              <eagle-row class="dep_sort">
                <eagle-col span="24">
                  <img
                    class="icon"
                    src="@/assets/Images/AppIcon/icon_list_date.png"
                    alt=""
                  />最近修改日期：{{ item.EditDate | formatDateTime }}
                </eagle-col>
              </eagle-row>
              <eagle-row
                gutter="20"
                class="dep_sort"
              >
                <eagle-col span="24">
                  <div style="display: flex">
                    <div style="width: 80px">签名文件：</div>
                    <div style="flex: 1; overflow: hidden; margin-right: 5px">
                      <div :key="index">
                        <div
                          style="color: #1989fa"
                          @click.stop="lookPdf(item, '')"
                        >
                          {{ item.TemplateName }}
                        </div>
                      </div>
                    </div>
                  </div>
                </eagle-col>
              </eagle-row>
            </div>
            <van-divider />
            <div class="op_btn">
              <div
                class="btn_item"
                @click.stop="lookPdf(item)"
              >
                <img
                  src="@/assets/Images/AppIcon/icon_list_edit.png"
                  alt=""
                />
                <div class="mr-10">签名</div>
              </div>

            </div>
          </div>
        </eagle-cell>
      </div>
    </eagle-list>
  </div>
</template>

<script>
export default {
  data() {
    return {
      active: 0,
      list: [],
      filterTab: true,
      placeholder1: "",
      tabData: [
        {
          title: "岗位安全生产责任书",
          url: "/ResponsibilityOrgPostUserDepositManage/GetPageData",
          isPage: true,
          params: {
            dataType: "DepositManage",
          },
        },
        {
          title: "责任制文件",
          url: "/ProjectEntrustedOnlineDoc/GetPageData",
          isPage: true,
          params: {
            dataType: "List",
            menuNo: "0202",
          },
        },
      ],
      filterParams: [
        {
          name: "Status",
          title: "状态",
          originTitle: "状态",
          dataType: "int",
          data: [
            { text: "不限", value: "" },
            { text: "现行", value: "10" },
            { text: "废止", value: "-1" },
          ],
        },
      ],
      filterTabDefault:[{ name: "Status", value: "10" }],
    };
  },
  created() {
    this.placeholder1 = "请输入岗位,姓名搜索";
  },
  methods: {
    _initActive(active) {
      if (active === 0) {
        this.$refs.eaglelist.changefilterTab(true);
        this.placeholder1 = "请输入岗位,姓名搜索";
      }
      if (active === 1) {
        this.$refs.eaglelist.changefilterTab(false);
        this.placeholder1 = "请输入文件名称搜索";
      }
      this.active = active;
    },
    bindData(data) {
      this.list = data;
    },
    goToDetail(item) {
      this.$router.push({
        path: "/ProductionSafetyView",
        query: { id: item.ID },
      });
    },

    goToEdit(item) {
      this.$router.push({
        path: "/ProductionSafetyEdit",
        query: { id: item.ID },
      });
    },
    // 新增/编辑
    add() {
      this.$router.push({
        path: "/ProductionSafetyAdd",
        query: { id: 0 },
      });
    },

    del(item) {
      const _this = this;
      this.$dialog
        .confirm({
          title: "询问",
          message: "您确定废止本条信息吗？",
        })
        .then(() => {
          _this.$axios
            .get("/ResponsibilityOrgPostUserDepositManage/Abolish", { params: { id: item.ID } })
            .then((res) => {
              _this.$toast.success("废止成功！");
              setTimeout(() => {
                _this.$refs.eaglelist.getList();
              }, 300);
            })
            .catch((err) => {
              console.log("err", err);
            });
        })
        .catch(() => {
          // on cancel
        });
    },

    // 附件详情

    goFile(attachCode) {
      this.$router.push("/Attach/AatachDetail?attCode=" + attachCode);
    },

    // 查看报告
    lookPdf(item, ids) {
      this.$router.push({
        name: "CheckReportDetail2",
        query: {
          url: process.env.VUE_APP_BASE_API + item.PdfAttach,
          TypeName: this.titleCode,
          isSignature: "ResponsibilityOrgPostUserDepositManage",
          IDS: ids,
          DocCode: item.Code,
        },
      });
    },
  },
};
</script>

<style lang="less" scoped>
.phone {
  position: relative;
  .code {
    position: absolute;
    right: 20px;
    top: 20px;
    font-size: 12px;
  }
}
.register-info {
  background-color: #e8f1f8;
  padding-bottom: 20px;
}
.img-box {
  height: 50px;
  width: 50px;
  padding: 10px;
  position: absolute;
  left: 50%;
  top: 60px;
  background-color: #fff;
  border-radius: 50%;
  overflow: hidden;
}
.popup-title {
  line-height: 35px;
  padding: 10px;
  font-size: 15px;
  padding-left: 20px;
}

.op_btn {
  display: flex;
  justify-content: flex-end;
  .btn_item {
    display: flex;
    align-items: center;
    img {
      height: 15px;
      width: 15px;
      margin-right: 5px;
    }
  }
}
</style>
